//********************************************************************************************************
// Product Name: MapWindow.dll Alpha
// Description:  The basic module for MapWindow version 6.0
//********************************************************************************************************
// The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); 
// you may not use this file except in compliance with the License. You may obtain a copy of the License at 
// http://www.mozilla.org/MPL/ 
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 
// ANY KIND, either expressed or implied. See the License for the specificlanguage governing rights and 
// limitations under the License. 
//
// The Original Code is from MapWindow.dll version 6.0
//
// The Initial Developer of this Original Code is Ted Dunsford. Created 6/9/2008 10:49:54 AM
// 
// Contributor(s): (Open source contributors should list themselves and their modifications here). 
//
//********************************************************************************************************

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

using MapWindow.Geometries;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace MapWindow.DirectX
{


    /// <summary>
    /// ColoredLineCollection
    /// </summary>
    public class PositionColoredVC : VertexCollection
    {
        #region Private Variables

        private Color _color;
        private List<Coordinate> _coordinates;


        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new, empty Colored Line list
        /// </summary>
        public PositionColoredVC()
        {
            Format = CustomVertex.PositionColored.Format;
            Vertices = new System.Collections.ArrayList();
            DrawBox = new DrawBox(-180d, 180d, -90d, 90d, -100d, 100d);
            _coordinates = new List<Coordinate>();
        }

        /// <summary>
        /// Creates a new vertex collection using the specified color
        /// </summary>
        /// <param name="color"></param>
        public PositionColoredVC(Color color)
        {
            Format = CustomVertex.PositionColored.Format;
            Vertices = new System.Collections.ArrayList();
            _color = color;
            DrawBox = new DrawBox(-180d, 180d, -90d, 90d, -100d, 100d);
            _coordinates = new List<Coordinate>();
        }

         /// <summary>
        /// Creates the necessary vertices using coordinates.
        /// This assumes the coordinates have already been organized to form
        /// the necessary structures.
        /// </summary>
        public PositionColoredVC(List<Coordinate> coordinates)
        {
            Format = CustomVertex.PositionColored.Format;
            Vertices = new System.Collections.ArrayList();
            DrawBox = new DrawBox(-180d, 180d, -90d, 90d, -100d, 100d);
            _coordinates = new List<Coordinate>();
            foreach (Coordinate coord in coordinates)
            {
                AddCoordinate(coord);
            }
        }

        /// <summary>
        /// Adds an individual vertex using the specified CoordinateF
        /// </summary>
        /// <param name="coord">The coordinate to add to the list</param>
        public override void AddCoordinate(Coordinate coord)
        {
            _coordinates.Add(coord);
            CustomVertex.PositionColored vert = new CustomVertex.PositionColored(base.DrawBox.ProjToView(coord), _color.ToArgb());
            vert.Z = 0f;
            Vertices.Add(vert);
        }

      

       

        #endregion

        #region Methods

        /// <summary>
        /// Assigns the values to a new vertex buffer
        /// </summary>
        protected override void Initialize()
        {
            Dispose();
            Vertices = new System.Collections.ArrayList();
            foreach (Coordinate coord in _coordinates)
            {
                CustomVertex.PositionColored vert = new CustomVertex.PositionColored(base.DrawBox.ProjToView(coord), _color.ToArgb());
                vert.Z = 0f;
                Vertices.Add(vert);
            }
            // This is specifically set up for the Lines
            //VertexBuffer = new VertexBuffer(DeviceDX, Vertices.Count, Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Managed);
            VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), Vertices.Count, DeviceDX, Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Managed);
            base.Initialize();
        }

        
        

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the color that should be used for all the vertices.
        /// </summary>
        public Color Color
        {
            get { return _color; }
            set { _color = value; }
        }

        
     
       


        #endregion



    }
}
